package com.jblv.frame.common.utils.jwt.jackjson;

import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.Map;

/**
 * @author happyonion.yangtao
 * @version 1.0
 * @title JacksonJsonParser
 * @projectName jblv-frame
 * @packageName com.jblv.common.utils.jwt.jackjson
 * @description JacksonJsonParser
 * @date Create at 2020/4/30 23:24
 * @since jdk1.8
 */
public class JacksonJsonParser implements JsonParser {
    private ObjectMapper mapper = new ObjectMapper();

    public JacksonJsonParser() {
    }

    public Map<String, Object> parseMap(String json) {
        try {
            return (Map)this.mapper.readValue(json, Map.class);
        } catch (Exception var3) {
            throw new IllegalArgumentException("Cannot parse json", var3);
        }
    }

    public String formatMap(Map<String, ?> map) {
        try {
            return this.mapper.writeValueAsString(map);
        } catch (Exception var3) {
            throw new IllegalArgumentException("Cannot format json", var3);
        }
    }
}
